package com.atguigu.crowd.service.impl;

import com.atguigu.crowd.entity.Auth;
import com.atguigu.crowd.entity.AuthExample;
import com.atguigu.crowd.mapper.AuthMapper;
import com.atguigu.crowd.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author zwj
 * @create 2021-07-21-11:48
 */
@Service
public class AuthServiceImpl implements AuthService {
    @Autowired
    private AuthMapper authMapper;
    @Override
    public List<Auth> getAll() {
        return authMapper.selectByExample(new AuthExample());
    }

    @Override
    public List<Integer> getAssignAuthIdByRoleId(Integer roleId) {
        List<Integer> list = authMapper.selectAssignAuthIdByRoleId(roleId);
        return list;
    }

    @Override
    public void saveRoleAuthRelationship(Map<String, List<Integer>> map){
        List<Integer> roleIdList = map.get("roleId");
        Integer roleId = roleIdList.get(0);

         authMapper.deleteOldRelationship(roleId);

        List<Integer> authIdArray = map.get("authIdArray");
        if (authIdArray != null && authIdArray.size() >0) {
            authMapper.insertnewRelationship(roleId,authIdArray);
        }
    }

    @Override
    public List<String> getAssignedAuthNameByAdminId(Integer adminId) {

        return authMapper.selectAssignedAuthNameByAdminId(adminId);
    }
}
